package etnorservice.etnor_service.mapper;

import etnorservice.etnor_service.domain.dto.ApiCountDTO;
import etnorservice.etnor_service.domain.dto.ParamsDTO;
import etnorservice.etnor_service.domain.po.*;
import etnorservice.etnor_service.domain.vo.ApiAduit;
import etnorservice.etnor_service.domain.vo.ApiManagementVO;
import etnorservice.etnor_service.domain.vo.ApiReviewVO;
import etnorservice.etnor_service.domain.vo.ApiSelectByTalentIdVO;
import etnorservice.etnor_service.request.ApiRejectRequest;
import etnorservice.etnor_service.request.ApiSearchRequest;
import lombok.Data;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.core.parameters.P;

import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author cc
 * @since 2024-06-30
 */
@Mapper
public interface ApiMapper{
   List<ApiDTO> getAllApis();
   List<ApiDTO> getAllApi();
   List<ApiDTO> getApisByKewordsAndCatelog(@Param("keywords") String keywords, @Param("catelog") String catelog);
   List<ApiCategory> findAllCatelogies();
   List<ApiSelectByTalentIdVO> getApiByTalentId(@Param("talentId") int talentId);
   int insertApi(ApiDTO apiDTO);
   List<ApiReviewVO> findReviewApi();
   List<ModeStatusNoteDTO> findModes();
   ModeStatusNoteDTO findCurrentMode();
   int changeMode(@Param("modeid") Integer modeid);
   int passApiReview(@Param("apiid") Long apiid);
   int updateAuditPass(@Param("apiid") Long apiid);
   int rejectApiReview(@Param("apiid") Long apiid);
   int updateAuditReject(@Param("apiid") Long apiid,@Param("comment") String comment);
   int insertApiRejection(ApiRejectRequest apiRejectRequest);
   List<ApiAduit>getAduitList(@Param("talentId") Integer talentId);
   ApiDTO findApiByid(@Param("id") Integer id);
   /*策略相关接口*/
   List<ApiShutdownPolicy> findAllPolicy();
   List<ApiAlarmPolicy> findAllAlarmPolicy();
   int publishApi(ApiPublish apiPublish);
   int changeApiStatus(@Param("apiid") Long apiid,@Param("status") Integer status);
   int changeAuditStatus(@Param("apiid") Long apiid,@Param("status") Integer status);
   ApiDTO findApiById(@Param("apiid") String apiid);
   List<RequestParam> findApiParams(@Param("apiId") String apiId);
   List<ApiBugLog> findApiBug (@Param("apiId") String apiId);
   List<RequestParam> findApiParamsOut(@Param("apiId") String apiId);
   String findApiTestUrl(@Param("apiid") String apiid);
   void apiLogSave(ApiLog apiLog);
   List<ApiLog> findLogs(@Param("apiid") String apiid);
   List<ApiManagementVO> findApiList(ApiSearchRequest apiSearchRequest);
   ApiCountDTO getApiCounts();
   List<ApiDTO> getApisByAccount(@Param("talentid") String talentid);
   List<ParamsDTO> getParams(@Param("apiid") String apiid);
   //新发布接口
   void publishApiByApiId(@Param("apiid") String apiid);

   void fullPublish(@Param("apiid") String apiid,
                    @Param("time") Date date,
                    @Param("talentId") String talentId);

   void insertParams(@Param("apiid") String apiid,
                     @Param("name") String name,
                     @Param("type") String type,
                     @Param("need") Integer need,
                     @Param("note") String note);
   void apiStatusChange(@Param("apiid") String apiid,@Param("status") Integer status);
   void rejectApi(ApiReject apiReject);
   ApiReject findReject(@Param("apiid") String apiid);
   List<ApiRequestStat> findApiRequestLog(@Param("apiid") String apiid);
   int insertApiRequestLog(ApiRequestLog apiRequestLog);
   Integer getApiCount(@Param("apiid") String apiid);
   List<ApiStatisticsDTO> getApiStatistics();

   void batchInsert(List<ApiParams> apiParams);

   int checkApiOwnership(@Param("apiId") Long apiId,@Param("account")String account);

   int checkApiExists(@Param("apiId") Long apiId);


   /**
    * 查询API总调用次数
    */
   int countApiCalls(String apiId);

   /**
    * 查询指定时间范围内的API调用次数
    */
   int countApiCallsByTimeRange(@Param("apiId") String apiId,
                                @Param("startTime") Date startTime,
                                @Param("endTime") Date endTime);

   /**
    * 查询API调用成功次数
    */
   int countSuccessfulApiCalls(String apiId);

   /**
    * 按天统计API调用次数
    */
   List<Map<String, Object>> countApiCallsByDay(@Param("apiId") String apiId,
                                                @Param("startTime") Date startTime,
                                                @Param("endTime") Date endTime);

   /**
    * 查询API平均响应时间
    */
   Long getAverageResponseTime(String apiId);


   /**
    * 查询API调用详细统计信息
    */
   Map<String, Object> getApiCallStats(String apiId);


   ApiToken findApiToken(@Param("apiid") Long apiid,@Param("userId") Long userId);

}
